/*
 * GMath.java
 * Created on 6 janv. 2008
 *
 * Glacéo Internet Platform
 * http://sourceforge.net/projects/chm/
 *
 * Copyright (c) 2005-2008, Jan Janke (VirtualHockey Project)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hockeo.vhbase.utils.lang;

/**
 * Collection of mathematical utiliy methods.
 *
 * @version $Id$
 * @author jjanke
 */
public final class GMath
{
  /**
   * Logarithm of 2 (base 10).
   */
  public static final double LOG10_2 = Math.log10( 2 );

  /** Private constructor to avoid instantiation. */
  private GMath()
  {}

  /**
   * Calculates f(x) for the following gauss distribution function:
   *
   * f(x) = k * ( ( 1 / ( s * sqrt(2pi) ) ) exp ( -1/2 * ( ( x - u ) / s ) pow 2 ) )
   *
   * @param x the value for which to calculate the gaussian distribution
   * @param k multiplier for the function
   * @param s standard deviation (determines the straggling)
   * @param u expected value (determines the symmetric axis of the gaussian curve)
   * @return gauss value multiplied by k for the given x/k/s
   */
  public static double gauss( final double x, final double k, final double s, final double u )
  {
    return k * ( ( 1 / ( s * Math.sqrt( 2 * Math.PI ) ) ) * Math.pow( Math.E, -0.5 * Math.pow( ( x - u ) / s, 2 ) ) );
  }

  /**
   * Calculates the normal distribution for the given x (standard deviation 1 and expected
   * value 0).
   *
   * @param x the value for which to calculate the normal distribution.
   * @return the normal distribution for x
   */
  public static double normalDistribution( double x )
  {
    return gauss( x, 1, 1, 0 );
  }

  /**
   * Calculates f(x) for the following linear function:
   *
   * f(x) = k * ( m * x + n )
   *
   * @param x the value for which to calculate the function
   * @param k multiplier for the function
   * @param m ascension factor
   * @param n y-offset factor
   * @return linear function value
   */
  public static double linear( final double x, final double k, final double m, final double n )
  {
    return k * ( m * x + n );
  }
}
